/* * * * M A P V I S I O N   L I C E N S E  *****************************************************************
 *
 * This MapVision software is © Filip Zavadil 2013. It is licensed under the LGPL license.
 * This MapVision software dynamically links to unmodified Qt5 Library.
 *
 * The Qt5 Library is © 2013 Qt® and/or its subsidiary(-ies), and is licensed under the
 * GNU Lesser General Public License version 2.1 with Qt® LGPL exception version 1.1.
 * Qt5 library is free software; you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
 * Qt5 library is provided “AS IS”, without WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
 *
 * As an additional permission to the GNU Lesser General Public License version 2.1, the object
 * code form of a “work that uses the Library” may incorporate material from a header file that is
 * part of the Library. You may distribute such object code under terms of your choice,
 * provided that: (i) the header files of the Library have not been modified; and (ii)
 * the incorporated material is limited to numerical parameters, data structure layouts, accessors,
 * macros, inline functions and templates; and (iii) you comply with the terms of Section 6 of the
 * GNU Lesser General Public License version 2.1.
 *
 * Moreover, you may apply this exception to a modified version of the Library, provided that such
 * modification does not involve copying material from the Library into the modified Library’s header
 * files unless such material is limited to (i) numerical parameters; (ii) data structure layouts;
 * (iii) accessors; and (iv) small macros, templates and inline functions of five lines or less in length.
 *
 * Furthermore, you are not required to apply this additional permission to a modified version of the Library.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this package;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

 * The source code for Qt 5.X SDK is available from Qt Project here:
 * http://download.qt-project.org/official_releases/qtcreator/2.7/2.7.0/qt-creator-2.7.0-src.zip.
 *
 * ****************************** M A P V I S I O N    S O F T W A R E  ************************************
 *
 * Author:       Filip Zavadil
 * Description:  Software for displaying and exporting map tiles.
 * The sources and executables of MapVision software are available:
 *    - from project hosting on CodePlex.com :   http://mapvision.codeplex.com
 *    - from GIT repositories on Gitorious.org:  https://gitorious.org/mapvision
 * Visit MapVision fanpage on Facebook.com:      https://www.facebook.com/pages/Mapvision/631827753513935
 *
 * *********************************************************************************************************
*/

#include <QApplication>
#include "mapvision.h"
#include <QTranslator>
#include <QSettings>
#include <cmath>


class I : public QThread
{
public:
        static void sleep(unsigned long secs) {
                QThread::sleep(secs);
        }
};

int main(int argc, char *argv[])
{
    QCoreApplication::setOrganizationName("Zava");
    QCoreApplication::setOrganizationDomain("filipzava.cz");
    QCoreApplication::setApplicationName("MapVision");
    QCoreApplication::setApplicationVersion("0.8");


    QSettings settings;
    // first run
    if (settings.value("main/rendering")=="")
    {
        settings.setValue("main/rendering","AUTO");
        settings.setValue("main/openDokument","/home");
        settings.setValue("main/saveDokument","/home");
        settings.setValue("layer/TILESlocal","/home");
        settings.setValue("layer/SQLite","/home");
        settings.setValue("save/mapImage","/home");
    }
    // end first run

    qDebug()<<settings.value("main/language").toString();

    QApplication a(argc, argv);

    QTranslator translator;

    translator.load("lang_"+settings.value("main/language").toString());

    a.installTranslator(&translator);


    QPixmap pixmap("images/startUpScreen.png");
    QSplashScreen splash(pixmap, Qt::WindowStaysOnTopHint);
    splash.show();
    splash.showMessage(QObject::tr("wait please, the application is loading ... "));
    a.processEvents();

    a.setStyle("fusion");

    a.setStyleSheet(
                "QMenuBar        {background-color: rgb(103, 103, 103); color: white}"
                "QMainWindow, QWidget, QDialog, QStackedWidget { background-color: rgb(103, 103, 103)}"
                "QGroupBox   { border: 1px solid black; border-radius: 5px; margin-top: 1ex; padding-top: 10px}"
                "QGraphicsView   { border: 1px solid black;background-color: rgb(68, 68, 66)}"
                "QMenu   { border: 1px solid black;background-color: rgb(103, 103, 103)}"
                "QToolButton,QPushButton  { background-color: rgb(68, 68, 66); color: rgb(232, 232, 232); }"
                "Line  { background-color: rgb(103, 103, 103); color: black  }"
                "QLineEdit, QSpinBox, QTextBrowser, QTextEdit, QPlainTextEdit      { background-color: rgb(133, 133, 133); color: black  }"
                "QMainWindow::separator:horizontal{ background: rgb(103, 103, 103); max-width: 2px;width: 2px;border-top: 1px solid #393939;border-bottom: 1px solid #959595;}"
                "QMainWindow::separator:vertical { background: rgb(103, 103, 103); max-height: 2px; height: 2px; border-left: 1px solid #393939; border-right: 1px solid #959595}"
                "QMainWindow::separator:hover{ background: #686868;}"
                "QGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left;}"
                "QListWidget#listWidgetLayers::item:selected { border: 0px solid #6a6ea9;}"
                "QLabel#labelMapTitle { border: 1px solid black;}"
                "QWidget#dockWidgetTitleBar { border: 1px solid black;}"
                "QToolBar QToolButton {background-color: rgba(0,0,0,0)}"
                "QToolbar,QDockWidget {background: rgb(130,130,130)}"
                "QGraphicsWebView {background-color: rgb(68, 68, 66);}"
                );


    MapVision w;
    //w.resize(600, 500);
    I::sleep(3);
    w.showMaximized();
    splash.finish(&w);


    /*  **********  SETTINGS *************
     *  settings: key        |  data type
     *  main/language        |  QString (ISO 639: Two-letter Language Codes)
     *  main/lastProjects    |  QStringList (filepaths)
     *  main/lastOpen        |  QStringList (filepaths)
     *  loader/lastTMSlocal  |  QString
     *  loader/lastWMTSlocal |  QString
     *  main/rendering       |  QString (current, concurrent, auto)
     */

    /* **********  MAP FILE *************
     * xml map document (mvd) which describes map project
     *
    *  Project  -   name
    *           -   description
    *           -   date of creation
    *           -   date of saving
    *           -   owner / edited by / creator
    *           -   area ?
    *           -   origin zoom / last
    *           -   origin point
    *           -   layers
    *               - layer
    *                       - type
    *                       - layer name
    *                       - source
    *                       - origin
    *                       - transparency
    */

    return a.exec();
}

